package com.corpdata.system.org.service.impl;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.corpdata.common.api.pagehelper.PageConvertUtil;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.common.utils.CorpdataUtil;
import com.corpdata.core.base.AbstractBaseService;
import com.corpdata.system.org.dao.UserDeptMapper;
import com.corpdata.system.org.entity.UserDept;
import com.corpdata.system.org.service.UserDeptService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 员工部门关联
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-12 09:19:06
 */
@Service
@Transactional
public class UserDeptServiceImpl extends AbstractBaseService<UserDept> implements UserDeptService {
	
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());  
	
	@Autowired
	private UserDeptMapper userDeptMapper;
	
	public Result insert(String userid,String deptids) {
		deleteById(userid);
		Result ret=null;
		String[] deptid=deptids.split(",");
		for(String dept:deptid){
			UserDept record=new UserDept();
			Date date = new Date();
			record.setId(CorpdataUtil.getUUID());
			record.setFkUser(userid);
			record.setFkDept(dept);
			ret=super.save(record);
		}
		return ret;
	}
	
	public String findByIdsDept(String ids) {
		String deptId="";
		List<UserDept> lists=super.findByIds(ids);
        for(UserDept list:lists){
        	deptId+=","+list.getFkDept();
        }
        if(deptId!=""){
        	deptId=deptId.substring(1);
        }
		return deptId;
    }
	
}
